﻿

    public interface IOrderService
    {
        string CreateOrder(int ProductId);
    }
    public class OrderService : IOrderService
    {
        private readonly IInventoryService _inv;
        private readonly ILogger<IOrderService> _log;//声明记录IOrderService的工具
        public OrderService(IInventoryService inv, ILogger<IOrderService> log)
        {
            _inv = inv; //转换如果转换失败不会抛出异常
            _log = log;
        }
        public string CreateOrder(int ProductId)
        {
            _log.LogInformation("创建订单{ProductId}", ProductId);
            return _inv.CheckStock(ProductId) ?  $"订单创建成功（产品{ProductId})" : $"库存不足(产品{ProductId})";

        }
    }
